package com.paipaideli.ui.mine.help;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jakewharton.rxbinding2.view.RxView;
import com.paipaideli.BuildConfig;
import com.paipaideli.R;
import com.paipaideli.common.base.BasePresenterActivity;
import com.paipaideli.common.views.CommonDialogView;
import com.paipaideli.ui.mine.head.InvestActivity;
import com.paipaideli.ui.price.PriceActivity;
import com.paipaideli.ui.webView.WebAcyivity;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 帮助中心
 */
public class HelpCenterActivity extends BasePresenterActivity implements View.OnClickListener {

    Unbinder unbinder;
    @BindView(R.id.top_back)
    RelativeLayout top_back;
    @BindView(R.id.top_title)
    TextView top_title;
    @BindView(R.id.lin_help_lxkf)
    LinearLayout lin_help_lxkf;
    @BindView(R.id.lin_help_cjwt)
    LinearLayout lin_help_cjwt;
    @BindView(R.id.lin_help_hqsyczlc)
    LinearLayout lin_help_hqsyczlc;
    @BindView(R.id.lin_help_cjpmczlc)
    LinearLayout lin_help_cjpmczlc;
    @BindView(R.id.lin_help_dlzcczlc)
    LinearLayout lin_help_dlzcczlc;
    @BindView(R.id.lin_help_bk)
    LinearLayout lin_help_bk;
    @BindView(R.id.lin_help_tglc)
    LinearLayout linHelpTglc;


    @Override
    public int getContentView() {
        return R.layout.activity_help;
    }

    @Override
    public void initView() {
        unbinder = ButterKnife.bind(this);
        top_title.setText("帮助中心");

        top_back.setOnClickListener(this::onClick);
        lin_help_lxkf.setOnClickListener(this::onClick);
        lin_help_cjwt.setOnClickListener(this::onClick);
        lin_help_hqsyczlc.setOnClickListener(this::onClick);
        lin_help_cjpmczlc.setOnClickListener(this::onClick);
        lin_help_dlzcczlc.setOnClickListener(this::onClick);
        lin_help_bk.setOnClickListener(this::onClick);
        linHelpTglc.setOnClickListener(this::onClick);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.top_back:
                finish();
                break;
            case R.id.lin_help_lxkf:
                showCall();
                break;
            case R.id.lin_help_cjwt:
                WebAcyivity.open(this, BuildConfig.h5 + "commonProblem.html", "常见问题");
                break;
            case R.id.lin_help_tglc:
                WebAcyivity.open(this, BuildConfig.h5 + "extension.html", "推广流程");
                break;
            case R.id.lin_help_hqsyczlc:
                WebAcyivity.open(this, BuildConfig.h5 + "cash.html", "获取收益操作流程");
                break;
            case R.id.lin_help_cjpmczlc:
                WebAcyivity.open(this, BuildConfig.h5 + "snatch.html", "参加拍卖操作流程");
                break;
            case R.id.lin_help_dlzcczlc:
                WebAcyivity.open(this, BuildConfig.h5 + "registerLC.html", "登录注册操作流程");
                break;
            case R.id.lin_help_bk:
                WebAcyivity.open(this, BuildConfig.h5 + "micropedia.html", "拍拍得利小百科");
                break;

        }

    }

    private void showCall() {
        final CommonDialogView dialog = new CommonDialogView(HelpCenterActivity.this);
        dialog.setMessage("是否拨打客服电话：400 033 1898")
                .setTitle("温馨提示")
                .setPositive("取消")
                .setNegtive("拨打电话")
                .setSingle(false).setOnClickBottomListener(new CommonDialogView.OnClickBottomListener() {
            @Override
            public void onPositiveClick() {
                dialog.dismiss();

            }

            @Override
            public void onNegtiveClick() {
                dialog.dismiss();
                Intent intent = new Intent(Intent.ACTION_DIAL);
                Uri data = Uri.parse("tel:" + "4000331898");
                intent.setData(data);
                startActivity(intent);
            }
        }).show();

//        Dialog dialog = new Dialog(HelpCenterActivity.this);
//        dialog.setCanceledOnTouchOutside(false);//点击空白区域不消失
//        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//        dialog.setContentView(R.layout.layout_dialog_twobtn);
//        Window dialogWindow = dialog.getWindow();
//        dialogWindow.setGravity(Gravity.CENTER);
//        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//        lp.width = WindowManager.LayoutParams.FILL_PARENT;
//        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        dialogWindow.setAttributes(lp);
//        dialog.show();
//        Button button1 = dialog.findViewById(R.id.dialog_btn_ok);
//        button1.setText("取消");
//        Button button2 = dialog.findViewById(R.id.dialog_btn_no);
//        button2.setText("拨打电话");
//        button2.setVisibility(View.VISIBLE);
//        TextView textView = dialog.findViewById(R.id.tv_dialog_title);
//        textView.setText("是否拨打客服电话：400 033 1898");
//
//        addDisposable(RxView.clicks(button1)
//                .throttleFirst(1, TimeUnit.SECONDS)
//                .subscribe(o -> {
//                    dialog.dismiss();
//                }));
//
//        addDisposable(RxView.clicks(button2)
//                .throttleFirst(1, TimeUnit.SECONDS)
//                .subscribe(o -> {
//                    dialog.dismiss();
//                    Intent intent = new Intent(Intent.ACTION_DIAL);
//                    Uri data = Uri.parse("tel:" + "4000331898");
//                    intent.setData(data);
//                    startActivity(intent);
//                }));
    }
}
